#include<iostream>
#include<cstring>
using namespace std;
const int maxn = 100005;
int a[maxn];
int n;
int f[maxn];

int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		f[i]=1926260817;
	}
	int len=1;
	f[1]=a[1];
	for(int i=2;i<=n;i++){
		int l=0,r=len,mid;
		if(a[i]>f[len])f[++len]=a[i];
		else{
			while(l<r){
				mid=(l+r)/2;
				if(f[mid]>a[i])r=mid;
				else l=mid+1;
			}
			f[l]=min(f[l],a[i]);
		}
	}
	cout<<len;
}
